package com.lzj.demo.jdbc;

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class BrandDelete {
    @Test
    public void testDelete() throws Exception {
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        //获取连接
        String url = "jdbc:mysql://120.76.73.12:3306/db1?useSSL=false&useServerPrepStmts=true&characterEncoding=utf8";
        String username = "root";
        String password = "";
        Connection conn = DriverManager.getConnection(url, username, password);
        //定义 delete sql语句
        String deleteSql = "delete from tb_brand where id = 3";
        Statement statement = conn.createStatement();
        int count = statement.executeUpdate(deleteSql);
        if(count > 0){
            System.out.println("操作结果:成功删除 "+count+" 行数据");
        }
    }
}
